AppUserView = Ext.extend(Ext.Panel, {
		constructor : function (a) {
			Ext.applyIf(this, a);
			this.initUIComponents();
			AppUserView.superclass.constructor.call(this, {
				id : "AppUserView",
				title : "账号信息",
				iconCls : "menu-AccountManagement",
				layout : "border",
				autoScroll : true
			});
		},
		initUIComponents : function () {
			this.initSearchPanel();
			this.initGridPanel();
			this.items = [this.searchPanel, this.gridPanel];
		},
		onSearch : function (c) {
			var a = Ext.getCmp("AppUserSearchForm");
			var b = Ext.getCmp("AppUserGrid");
			if (a.getForm().isValid()) {
				$search({
					searchPanel : a,
					gridPanel : b
				});
			}
		}
	});
AppUserView.prototype.initSearchPanel = function () {
	this.searchPanel = new Ext.FormPanel({
			region : "north",
			height : 35,
			frame : false,
			border : false,
			id : "AppUserSearchForm",
			layout : "hbox",
			layoutConfig : {
				padding : "5",
				align : "middle"
			},
			defaults : {
				xtype : "label",
				border : false,
				margins : {
					top : 0,
					right : 4,
					bottom : 4,
					left : 4
				}
			},
			items : [{
					text : "用户账号"
				}, {
					xtype : "textfield",
					name : "Q_username_S_LK"
				}, {
					text : "用户姓名"
				}, {
					xtype : "textfield",
					name : "Q_staff.name_S_LK"
				},{
					xtype : "button",
					text : "查询",
					iconCls : "search",
					scope : this,
					handler : this.onSearch.createCallback(this)
				}, {
					xtype : "button",
					text : "清空",
					scope : this,
					iconCls : "reset",
					handler : Appreset
				}
			]
		});
};
AppUserView.prototype.initGridPanel = function () {
	this.toolbar = new Ext.Toolbar({
			height : 30,
			items : []
		});
	if (isGranted("_AppUserAdd")) {
		this.toolbar.add(new Ext.Button({
				text : "添加账号",
				iconCls : "add-user",
				handler : function () {
					new AppUserForm({}).show();
				}
			}));
	}
	if (isGranted("_AppUserDel")) {
		this.toolbar.add(new Ext.Button({
				iconCls : "btn-delete",
				text : "删除账号",
				handler : function () {
					var h = Ext.getCmp("AppUserGrid");
					var d = h.getSelectionModel().getSelections();
					if (d.length == 0) {
						Ext.ux.Toast.msg("信息", "请选择要删除的记录！");
						return;
					}
					var ids = "";
					for (var i = 0; i < d.length; i++) {
						if (d[i].data.userName == 'admin') {
							Ext.ux.Toast.msg("超级管理员不能被删除！");
						} else {
							ids += d[i].data.userId
							if (i < d.length - 1) {
								ids = ids + ",";
							}
						}
					}
					if (ids) {
						AppUserView.remove(ids);
					}
				}
			}));
	}
	var b = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				url : __ctxPath + "/system/listAppUser.do"
			}),
			reader : new Ext.data.JsonReader({
				root : "result",
				totalProperty : "totalCounts",
				fields : [{
						name : "userId",
						type : "int"
					}, "username", "password", "staff"]
			}),
			remoteSort : true
		});
	b.setDefaultSort("userId", "desc");
	b.load({
		params : {
			start : 0,
			limit : 25
		}
	});
	var e = new Ext.grid.CheckboxSelectionModel();
	var a = new Ext.grid.ColumnModel({
			columns : [
				e,
				new Ext.grid.RowNumberer(), {
					header : "userId",
					dataIndex : "userId",
					hidden : true
				},
				/*{
				header : "状态",
				dataIndex : "status",
				width : 30,
				renderer : function(f) {
				var g = "";
				if (f == "1") {
				g += '<img title="激活" src="'
				+ __ctxPath
				+ '/resources/images/flag/customer/effective.png"/>';
				} else {
				g += '<img title="禁用" src="'
				+ __ctxPath
				+ '/resources/images/flag/customer/invalid.png"/>';
				}
				return g;
				}
				},*/
				{
					header : "账号",
					dataIndex : "username",
					width : 60
				}, {
					header : "姓名",
					dataIndex : "staff",
					width : 60,
					renderer : function (f) {
						if (f == null) {
							return "";
						} else {
							return f.name;
						}
					}
				}, /*{
				header : "地址",
				dataIndex : "address",
				hidden : true,
				exprint : true
				},{
				header : "用户名",
				dataIndex : "fullname",
				width : 60
				},{
				header : "邮箱",
				dataIndex : "email",
				width : 120
				},{
				header : "所属部门",
				dataIndex : "department",
				renderer : function(f) {
				if (f == null) {
				return "";
				} else {
				return f.depName;
				}
				},
				width : 60
				},{
				header : "所在职位",
				dataIndex : "job",
				renderer : function(f) {
				if (f == null) {
				return "";
				} else {
				return f.jobName;
				}
				},
				width : 60
				},{
				header : "入职时间",
				dataIndex : "accessionTime",
				width : 100
				},*/
				{
					header : "管理",
					dataIndex : "userId",
					sortable : false,
					width : 60,
					renderer : function (j, i, g, m, h) {
						var l = g.data.userId;
						var f = g.data.username;
						var k = "";
						if (l != 1) {
							if (isGranted("_AppUserDel")) {
								k += '<button title="删除" value=" " class="btn-delete" onclick="AppUserView.remove('
								 + l + ')"></button>';
							}
							if (isGranted("_AppUserEdit")) {
								k += '&nbsp;<button title="编辑" value=" " class="btn-edit" onclick="AppUserView.edit('
								+ l + ')"></button>';
								}
							if (isGranted("_AppUserReset")) {
								k += '&nbsp;<button title = "重置" value = " " class = "btn-password" onclick = "AppUserView.reset('
											+ l + ')" >  </button > ';
								}
							}
							return k;
						}
					} ],
							defaults : {
								sortable : true,
								menuDisabled : true,
								width : 100
							}
						});
							this.gridPanel = new Ext.grid.GridPanel({
								id : "AppUserGrid",
								tbar : this.toolbar,
								store : b,
								region : "center",
								shim : true,
								trackMouseOver : true,
								disableSelection : false,
								loadMask : true,
								cm : a,
								sm : e,
								viewConfig : {
									forceFit : true,
									enableRowBody : false,
									showPreview : false
								},
								bbar : new HT.PagingBar({
									store : b
								})
							});
						//	this.gridPanel.addListener("rowdblclick", d);
							var c = this.gridPanel;
							function d(g, f, h) {
								g.getSelectionModel().each(function(j) {
									var i = j.data.userId;
									if (isGranted("_AppUserEdit") && i != 1) {
										AppUserView.edit(i, j.data.username);
									}
								});
							}
						};
									AppUserView.remove = function(a) {
										Ext.Msg.confirm("删除操作", "你确定要删除该用户吗?", function(b) {
											if (b == "yes") {
												Ext.Ajax.request({
													url : __ctxPath + "/system/deleteAppUser.do",
													method : "post",
													params : {
														ids : a
													},
													success : function(d) {
														var c = Ext.util.JSON.decode(d.responseText);
														if (c.msg==null) {
															Ext.ux.Toast.msg("操作提示", "用户删除成功");
														} else {
															Ext.ux.Toast.msg("操作提示", c.msg);
														}
														Ext.getCmp("AppUserGrid").getStore().reload();
													},
													failure : function() {
														Ext.ux.Toast.msg("操作提示", "用户删除失败");
													}
												});
											}
										});
									};
									AppUserView.reset = function(a) {
										new setPasswordForm(a);
									};
									Appreset = function(){
										var a=Ext.getCmp("AppUserSearchForm");
										a.getForm().reset();
									}
									AppUserView.edit = function(id) {
										new AppUserForm({
											userId : id
										}).show();
									};
